<?php
/**
 * 订单汇总
 */
class indentsumController extends baseController {

	public function month(){
		$month = intval(str_replace('-','',fetch_a_string('month')));
		$list  = IndentHelper::getMonthSummary($month);
                
		if($list[2])
			$dlist = array_intersect_key(Dept::getHashList(), array_flip($list[2]));
		else
			$dlist = Dept::getHashList();
                
                $now = fetch_a_string('month')?fetch_a_string('month'):"now";
                $lastdate = fetch_a_string('from')?fetch_a_string('from'):date("Y-m-1",strtotime($now));
                $nextdate = fetch_a_string('to')?fetch_a_string('to'):date("Y-m-t",strtotime($now));
                $this->assign('lastdate',  $lastdate);
                $this->assign('nextdate',  $nextdate);
		$this->assign('dlist',  $dlist);
		$this->assign('list', $list[0]);
		$this->assign('demandtypes', $list[1]);
		$this->assign('sumtotal', array_sum($list[1]));
		$this->display();
	}
	
	public function year(){
		$year = fetch_a_int('year') ?: date('Y');
		
		$list = IndentHelper::getYearSummary($year);
//		Debug::pre($list);
		$this->assign('data', $list);
		$this->assign('months', range(1,12));
		$this->assign('year', $year);
		$this->assign('depts', Dept::getList());
		$this->assign('suppliers', Supplier::getList());
		$this->display();
	}
	
	/**
	 * 汇总订单明细 
	 */
	public function detail(){
		$month = intval(str_replace('-','',fetch_a_string('month')));
		$list = IndentHelper::getDetailSummary($month);
//		Debug::pre($list);
		$this->assign('summary', array('items'=>$list));
		$this->display();
	}
	
}
?>
